const { toLog } = require("./common/common");

class User {
    constructor() {

    }

    //创建用户
    async createUser(name, password, auth, sign) {
        //root用户不允许创建
        if (name === 'root') {
            throw ('USER_EXISTS');
        }
        try {
            auth = auth || 'default';
            let todo = `insert into User.user (name,password,auth) values ('${name}','${password}','${auth}')`;
            let par = sql.parseSql(todo);
            await sql.doSql(par, sign);
        } catch (res) {
            //去捕获错误
            toLog("res = ", res);
            if (res === 'KEY_EXIST') {
                throw ('USER_EXISTS');
            }
            throw (res);
        }
    }

}


module.exports = User;